##Turn on the constraint
oo::define Charmm method turnon { module args} {
    eval "$module configure $args "
    my sendCmd [$module onCmd [self]]
}
##Turn off the constraint
oo::define Charmm method turnoff { module} {
    my sendCmd [$module offCmd]
}
class create GeoCons {
    constructor { {conf {}} } {
     my variable configuration
     array set configuration $conf
    }
}

# core

# setup
oo::define GeoCons method configure args {
  my variable configuration
  array set configuration $args
}

# helper
oo::define GeoCons method onCmd {operator} {
   my variable configuration 
   set cmd "MMFP\n"
   if [info exists configuration(type)] { set type $configuration(type)} else {
    set i 0
   set specified {}
   foreach direction {-x -y -z} {
     if [info exists configuration($direction)] {incr i; lappend specified [string range $direction end end]}
   }
   switch $i {
       0 { puts "warning:no reference position setup!";set type sphere}
       1 { set type plane;}
       2 { set type cylinder}
       3 {set type sphere}
   }
   }
   if [info exists configuration(individual)] { if [[string compare $configuration(atoms) yes]==0] { set rcm "" } } else {set rcm "rcm"}
   if [info exists configuration(apply2)] {set selection $configuration(apply2)} else {set selection "sele all end"}
   if [info exists configuration(force)] { set force $configuration(force)} else {set force 0.0}
   set com [$operator getCOM all] 
   if [info exists configuration(-x)] { set x $configuration(-x)} else {set x [lindex $com 0]}
   if [info exists configuration(-y)] { set y $configuration(-y)} else {set y [lindex $com 1]}
   if [info exists configuration(-z)] { set z $configuration(-z)} else {set z [lindex $com 2]}
  
   switch $type {
     sphere {
      set vector ""
      if [info exists configuration(radius)] {set droff  $configuration(radius)}
     }
     plane {
     set vector ""
      foreach direction $specified {
       append vector "${direction}dir 1.0" 
      }
      if [info exists configuration(window)] {set droff  $configuration(window)}
     }
     cylinder {
     set vector ""
     foreach direction {x y z} {
      if {[lsearch $specified $direction] <0} {
       append vector "${direction}dir 1.0"
      }
     }
       if [info exists configuration(radius)] {set droff  $configuration(radius)}
     }
   }
   set cmd "mmfp\ngeo $type $rcm force $force -\n xref $x yref $y zref $z $vector droff $droff -\n $selection\n end"
}
oo::define GeoCons method offCmd {} {
   set cmd {MMFP
     GEO reset
     end
   }
   return $cmd
}
